﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpaceHero.Screens
{
    class MainMenuScreen
    {
        int [,] world;
        Player player;
        Matrix transform;

        Texture2D blank;

        public MainMenuScreen(GraphicsDeviceManager graphics)
        {
            world = CreateWorld(200);
            player = new Player(new Vector2(0, 0), world);
        }

        public void LoadContent(ContentManager content)
        {
            player.LoadContent(content);
            blank = content.Load<Texture2D>("blank");
        }

        public void Update(GameTime gameTime, StateManager stateManager, KeyboardState keyState, KeyboardState oldKeyState)
        {
            player.Update(gameTime, keyState, oldKeyState, world);
            transform = Matrix.CreateTranslation(new Vector3(-player.followPosition, 0));
        }

        public void Draw(GraphicsDeviceManager graphics, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, transform * Matrix.CreateTranslation(new Vector3(new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2), 0)));
            //TODO Draw World
            player.Draw(graphics, spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin();
            //TODO Draw HUD
            spriteBatch.End();
        }

        public int[,] CreateWorld(int size)
        {
            WorldGenerator.WorldGenerator worldGenerator = new WorldGenerator.WorldGenerator();
            world = new int[size,size];
            world = worldGenerator.GenerateWorld(size);
            return world;
        }
    }
}